home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / TURB_VIS / TVG121 / TVGRAPH.TXT < prev   
Text File  |  1994-05-27  |  14KB  |  406 lines

  1. Introduction
  2. ============
  3. TVGraph is designed as a simple add in for any TurboVision application written
  4. for Turbo Pascal 6.0, Turbo Pascal 7.0, Borland Pascal 7.0 and Borland C++
  5. 3.1. It performs two major functions, firstly it intercepts all necessary
  6. functions to allow your entire application to perform effectively unchanged -
  7. but in graphics mode. The other major function is the provision of an
  8. infrastructure for performing graphics oriented functions in a safe and
  9. transparent manner, including the provision of some graphic primitives and
  10. objects. Writing a TVG Application
  11.  
  12. Just Graphics Mode
  13. ==================
  14. To enable graphics mode in an existing application written for Turbovision,
  15. just use the object gApp instead of TApplication to base your application
  16. object on, then pass a parameter to the constructor on initialising that
  17. application object.
  18.  
  19. e.g. PASCAL :    pMyapplication:=New(tMyApplication,.Init(smVGA640x480x16));
  20.  
  21.      C++    :   class TVDemo : public TApplication (as normal)
  22.                 then
  23.  
  24.                  int TVGStartMode = smVGA640x480x16;
  25.  
  26.                  int main(int argc, char **argv)
  27.                  {
  28.                  ... as normal
  29.                  }
  30.  
  31. The graphics modes are
  32.  
  33.       smVGA320x200x16
  34.       smVGA640x200x16
  35.       smVGA640x350x16
  36.       smVGA640x480x16
  37.       smVesa800x600x16
  38.       smVesa1024x768x16
  39.       smVesa1280x1024x16
  40.  
  41. with the following modifiers
  42.  
  43.      smUseBGIInterface    - initialises graphics using BGI
  44.      smUseTVGInterface    - initialises graphics using BIOS/VESA
  45.  
  46. Note that only smVesa800x600x16 and below work in version 1.2, and
  47. smVGA320x200x16 doesn't work in BGI mode. Support for higher resolutions
  48. and mouse support in Vesa modes will be in version 1.3 .
  49.  
  50. Note for C++ users - ensure you #include <tvg.h> just after any point
  51. you normally would #include <tv.h>.
  52.  
  53.  
  54. PASCAL :
  55.  
  56. The modified Application object gApp has the following interface :
  57.  
  58.   pgApp = ^gApp;
  59.   gApp = object(TProgram)
  60.     GrMode:word;                 (* Graphics mode of application *)
  61.     Prodable:boolean;           (* Prodable is TRUE for continuous updating *)
  62.     constructor Init(Mode:word);
  63.     destructor Done; virtual;
  64.     procedure SetScreenMode(Mode: Word);
  65.     procedure Idle; virtual;
  66. {$IFDEF Ver70}
  67.     procedure Cascade;
  68.     procedure DosShell;
  69.     procedure GetTileRect(var R: TRect); virtual;
  70.     procedure HandleEvent(var Event: TEvent); virtual;
  71.     procedure Tile;
  72.     procedure WriteShellMsg; virtual;
  73. {$ENDIF}
  74.   end;
  75.  
  76. CPP :
  77. The normal TProgram class has had several methods modified to allow for
  78. the TVGraph modes. A global byte (boolean) Prodable controls if TProgram.Idle
  79. continuously updates graphics views (prods).
  80.  
  81.  
  82.  
  83. Add some graphics
  84. =================
  85. To add some graphics to your application, you must use gWindow and gView for
  86. all windows and views that have graphics. These are decendants of TWindow and
  87. TView but with some modifications, firstly the gWindow.
  88.  
  89. PASCAL :
  90.   pgWindow = ^gWindow;
  91.   gWindow = object(TWindow)
  92.     constructor Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Integer);
  93.     procedure ChangeBounds(var Bounds: TRect); virtual;
  94.     procedure HandleEvent(var Event:TEvent);virtual;
  95.     procedure GraphDraw;
  96.     procedure GraphClear;
  97.     procedure GraphProd;
  98.   end;
  99.  
  100. CPP :
  101.  
  102. public:
  103.     gWindow( const TRect& bounds,
  104.                 const char *aTitle,
  105.                 short aNumber);
  106.     ~gWindow();
  107.  
  108.     virtual void handleEvent(TEvent& event);
  109.     virtual void changeBounds( const TRect& bounds );
  110.  
  111.     void GraphDraw();
  112.     void GraphClear();
  113.     void GraphProd();
  114. };
  115.  
  116. The handleevent routine has been modified to take care of the new graphics oriented events, and three methods have been added for graphics functionality. Each of the Graph methods calls the corresponding method in all gViews within that window. ChangeBounds has been over-ridden to allow for correct handling of moving graphics windows.
  117.  
  118. Now for the gView :
  119.  
  120. PASCAL :
  121.   pgView = ^gView;
  122.   gView = object(TView)
  123.     GraphWindowId:byte; (* The graphics window Id for this view *)
  124.     DisplayList:TCollection; (* List of gObjects
  125.     constructor Init(Var Bounds:Trect);
  126.     destructor Done;virtual;
  127.     procedure GraphProd;
  128.     procedure GraphDraw;
  129.     procedure GraphClear;
  130.     procedure Draw; virtual;
  131.     procedure HandleEvent(var Event:TEvent); virtual;
  132.     procedure ChangeBounds(var Bounds: TRect); virtual;
  133.     procedure Insert(P:pgObject);
  134.     procedure Delete(P:pgObject);
  135.   end;
  136.  
  137. CPP :
  138.  
  139. class gView : public TView {
  140. public:
  141.     gView( const TRect& bounds );
  142.     ~gView();
  143.  
  144.     void Insert(gObject *P);
  145.     void Delete(gObject *P);
  146.     virtual void GraphProd();
  147.     virtual void GraphDraw();
  148.     void GraphClear();
  149.  
  150.     virtual void draw();
  151.     virtual void handleEvent(TEvent& event);
  152.     virtual void changeBounds( const TRect& bounds );
  153.  
  154.     byte GraphWindowId;
  155.     TNSCollection *DisplayList;
  156. };
  157.  
  158. The new data elements included here are the GraphWindowId value which keeps
  159. track of the graphics ID of this view. (See section on graphics ID for full
  160. explanation).
  161.  
  162. The most important item for drawing graphics is the DisplayList collection.
  163. This is a normal Turbovision collection of gObjects. You can easily insert
  164. gObjects using Insert and Delete methods, just as you would insert and delete
  165. other views into parent views.
  166.  
  167. The GraphClear method calls high speed horizontal line routines to clear the
  168. graphics view. The  GraphDraw and GraphProd  routines call corresponding
  169. routines for each gObject in the DisplayList. The gObject and it's decendants
  170. will be explained in the gObject section.
  171.  
  172. Note - you should not override the Draw routines in decendants of gView as the
  173. last call inside any gView needs to be to GraphDraw. You can do it but be
  174. careful.
  175.  
  176. To insert graphics into a gView just create an instance of a gObject and use
  177. the insert method of the parent gView.
  178.  
  179. e.g.
  180. PASCAL :
  181. constructor MygWindow.Init;
  182. var
  183.   R  : TRect;
  184.   GV : pgView;
  185.   PB : pBox;
  186. begin
  187.   R.Assign(0, 0, 34, 12);
  188.   TWindow.Init(R, 'Box', wnNoNumber);
  189.   GetExtent(R);
  190.   R.Grow(-1,-1);
  191.   GV:=New(pgView,Init(R));
  192.   PB:=New(pStyx,Init(5000,2000,8000,6000,14));
  193.      GV^.Insert(PB);    (* Insert gObject into gView *)
  194.      Insert(GV);        (* insert gView into gWindow *)
  195. end;
  196.  
  197. C++ :
  198. MygWindow::MygWindow() :
  199.     gWindow( TRect(0, 0, 34, 12), "Box", wnNoNumber ),
  200.     TWindowInit( &TStyxDemo::initFrame )
  201. {
  202.     gView *GV;
  203.     gBox *PB;
  204.     TRect r(getExtent());
  205.     r.grow(-1, -1);
  206.     GV=new gView(r);
  207.     PB=new gbox(5000,2000,8000,6000,14);
  208.         GV->Insert(STYX); // Insert gObject into gView
  209.         insert(GV);      // Insert gView into gWindow
  210. }
  211.  
  212. Now TVGraph will continually keep that graphic displayed and you need only
  213. call the gViews's GraphDraw and GraphClear routines when you change the
  214. objects and you wish to update them.
  215.  
  216. Add some moving graphics
  217. ========================
  218. The GraphProd method in the gWindow and gView implement a continuously
  219. updating graphic system. By setting the Prodable flag to true in the gApp
  220. decendant, the idle method will send a message to all gWindows and therefore
  221. to all gViews and eventually to all gObjects asking them to update there
  222. status. This prod routine need do nothing more than change the representation
  223. of the object - TVGraph will automatically call GraphProd and then update the
  224. screen by calling GraphDraw.
  225.  
  226. See STYX.PAS and/or STYX.CPP for a full moving graphic example.
  227.  
  228. The Graphics ID system explained
  229. ================================
  230. TVGraph keeps an internal map of each virtual character position on the
  231. screen. All "text" positions on the screen are given the graphics id of 0.
  232. Each new gView you create automatically gets a unique graphics id (between 1
  233. and 254). Whenever the gView draws itself - it does two things; first it
  234. updates the map to reflect it's graphics id, and second it draws all graphics
  235. associated with that view and it's graphics id. Thus (as can be seen in styx)
  236. no graphics from one view will write into anothers space and also no graphics
  237. will overwrite any menus or other standard TurboVision objects.
  238.  
  239. You shouldn't have to worry about graphics IDs, but it is useful to know what
  240. they do.
  241.  
  242. gObject - Object Oriented Graphics
  243. ==================================
  244. There are three graphics objects in this release the gLine, gBox and the root
  245. gObject. This will be extending with version 1.3.
  246.  
  247. In PASCAL the are :
  248.  
  249. the root graphics object :
  250.  
  251.   pgObject = ^gObject;
  252.   gObject = object(TObject)
  253.     Color:byte;
  254.     constructor Init(C:byte);
  255.     procedure GraphDraw(R:TRect); virtual;
  256.     procedure GraphProd; virtual;
  257.     procedure ChangeColor(C:Byte);
  258.   end;
  259.  
  260.  graphics line object 
  261.  
  262.   pgLine = ^gLine;
  263.   gLine = object(gObject)
  264.     Xa,Ya,Xb,Yb:integer;
  265.     constructor Init(X1,Y1,X2,Y2:integer;C:byte);
  266.     procedure GraphDraw(R:TRect); virtual;
  267.     procedure ChangeEnds(X1,Y1,X2,Y2:integer);
  268.     procedure ChangeEndsCopy(S:gLine);
  269.     procedure DeltaEnds(X1,Y1,X2,Y2:integer);
  270.   end;
  271.  
  272. graphics box object
  273.  
  274.   pgBox = ^gBox;
  275.   gBox = object(gLine)
  276.     procedure GraphDraw(R:TRect); virtual;
  277.   end;
  278.  
  279. in CPP :
  280.  
  281. class gObject : public TObject {
  282. public:
  283.     gObject(void)  { Color=0; }
  284.     gObject(byte C) { Color=C; };
  285.     virtual void GraphDraw(TRect& R) = 0;
  286.     virtual void GraphProd() { };
  287.     void ChangeColor(byte C) { Color=C; };
  288.  
  289.     byte Color;
  290. };
  291.  
  292. class gLine : public gObject {
  293. public:
  294.     gLine(void) : gObject(0) {Xa=Xb=Ya=Yb=0; };
  295.     gLine(int X1,int Y1,int X2,int Y2,byte C);
  296.     virtual void GraphDraw(TRect& R);
  297.     void ChangeEnds(int X1,int Y1,int X2,int Y2);
  298.     void ChangeEnds(gLine S);
  299.     void DeltaEnds(int X1,int Y1,int X2,int Y2);
  300.     int Xa,Ya,Xb,Yb;
  301. };
  302.  
  303. class gBox : public gLine {
  304. public:
  305.     gBox(void) : gLine() {};
  306.     gBox(int X1,int Y1,int X2,int Y2,byte C);
  307.     virtual void GraphDraw(TRect& R);
  308. };
  309.  
  310. These three graphics objects (and the gStyx in the demo) are simple
  311. examples of object oriented graphics under TVGraph. The two key things a
  312. gObject needs to be able to do are : draw itself, and prod itself, by
  313. explanation here is the gLine.GraphDraw.
  314.  
  315. PASCAL :
  316. procedure gLine.GraphDraw(R:TRect);
  317. var
  318.  X1,Y1,X2,Y2:integer;
  319. begin
  320.  GlobalToPhysical(R,Xa,Ya,X1,Y1);
  321.  GlobalToPhysical(R,Xb,Yb,X2,Y2);
  322.  DrawLine(X1,Y1,X2,Y2,Color);
  323. end;
  324.  
  325. C++
  326. void gLine::GraphDraw(TRect& R) {
  327.  int X1,Y1,X2,Y2;
  328.  GlobalToPhysical(R,Xa,Ya,X1,Y1);
  329.  GlobalToPhysical(R,Xb,Yb,X2,Y2);
  330.  DrawLine(X1,Y1,X2,Y2,Color);
  331. }
  332.  
  333. All gObjects must represent themselves for drawing in a graphics space 10000
  334. units wide and 7500 units high. (Defined by constants GraphMaxX and
  335. GraphMaxY). Then to draw itself, it is passed the rectangle that TVGraph
  336. assumes relates to that virtual co-ordinate system - allowing you to scale if
  337. you so wish.
  338.  
  339. To assist you in drawing, the following two primitives are provided :
  340.  
  341. PASCAL :
  342. procedure DrawLine(X1,Y1,X2,Y2:integer;Color:word);
  343. (* Draw a Line in screen co-ordinates of color Color *)
  344. procedure GlobalToPhysical(R:TRect;X0,Y0:integer;var X,Y:integer);
  345. (* Translate 10000x7500 co-ordinate in R to physical co-ordinate *)
  346.  
  347. CPP :
  348. extern void cdecl DrawLine(ushort x1, ushort y1,ushort x2,ushort y2, ushort color);
  349. // Draw a Line in screen co-ordinates of color Color
  350. extern void cdecl GlobalToPhysical(TRect R,int X0,int Y0,int *X,int *Y);
  351. // Translate 10000x7500 co-ordinate in R to physical co-ordinate
  352.  
  353. The Drawline primitive draws a line from X1,Y1 to X2,Y2 in screen co-ordinates
  354. in Color. It takes account of graphics ids and also of the mouse cursor.
  355.  
  356. GlobalToPhysical converts virtual co-ordinates X0,Y0 to screen co-ordinates
  357. X,Y assuming a text rectangle of R.
  358.  
  359. NOTES FOR ALL USERS
  360. ===================
  361. 1. The current release of MOUSE.COM (9.00) doesn't generate a mouse cursor
  362.    in non-VGA resolutions.
  363. 2. The next modifications to the product are as follows :
  364.    - Some minor - but annoying bug fixes       Version 1.3
  365.    - More gObjects (High priority)             Version 1.3
  366.    - Add full BGI support (High priority)      Version 2.0
  367.      (any BGI writers out there want to write a custom TVGRAPH.BGI for
  368.       royalty - contact me)
  369.    - Add > 800x600x16 support - i.e. break the 64k barrier. (Medium Priority)
  370.                                                Version 1.3
  371.    - Add 256 colour support (Medium Priority)  Version 2.0
  372.    - Fix mouse support in hires (Low priority) Version 1.4?
  373. 3. WHEN
  374.    I was 2 months out for this version - but i'll give it another go
  375.    Version 1.3 .. September ?
  376.    Version 1.4 .. ?
  377.    Version 2.0 .. Early 1994 ?
  378.    Cause I know how people like wrong dates more than none at all
  379.  
  380.  
  381. NOTES FOR C++ USERS
  382. ===================
  383. 1. Copy TVGRAPH.LIB into the same directory as TV.LIB and
  384.    TVG.H into the same directory as TV.H.
  385. 2. Just by inserting TVGRAPH.LIB before TV.LIB in your link command
  386.    your application will run in graphics mode with NO modifications.
  387.    To use graphics objects you will need to include TVG.H in the
  388.    source modules that need it.
  389. 3. The default value
  390.       int TVGStartMode=smVGA640x480x16;
  391.    is declared in TVGRAPH.LIB, if you wish to override this you
  392.    need to insert a redeclaration of the same variable in the first
  393.    module in the link statment (normally just before main()).
  394. 4. You may wish to turn of duplicate symbol warnings in your link stage as
  395.    many of TVGRAPH's methods are overrides of TV.LIB methods.
  396. 5. I don't have access to a VESA.BGI for BC 3.1++ (and the one from BP 7
  397.    doesn't work) so although support is there for VESA 800x600 BGI mode
  398.    it will not work as distributed. The vesa16 variable if declared and linked
  399.    before the internal one will be accessed by the BGI initialisation part
  400.    of TVGRAPH.
  401.  
  402.  UPDATES THIS VERSION
  403.  ====================
  404.  1.21               -   Added more advanced cursor routines to stop
  405.                         the cursor disappearing. Uses timer tick ($1C).
  406.